#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>

struct DSU {
  std::vector<int> parent, size;

  DSU(int n) : parent(n), size(n, 1) {
    for (int i = 0; i < n; i++)
      parent[i] = i;
  }

  int getRoot(int u) {
    while (parent[u] != u)
      u = parent[u];
    return u;
  }

  void unionRoots(int r1, int r2) {
    if (size[r1] > size[r2])
      std::swap(r1, r2);
    size[r2] += size[r1];
    parent[r1] = r2;
  }

  void tryUnion(int u1, int u2) {
    int r1 = getRoot(u1);
    int r2 = getRoot(u2);
    if (r1 != r2)
      unionRoots(r1, r2);
  }
  
};

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  std::vector<std::vector<bool> > a(n, std::vector<bool>(m));
  DSU dsu(n * m);
  std::vector<std::pair<int, int> > steps(k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &steps[i].first, &steps[i].second);
    --steps[i].first;
    --steps[i].second;
    a[steps[i].first][steps[i].second] = true;
  }
  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < m; j++)
      if (!a[i][j] && !a[i + 1][j])
        dsu.tryUnion(i * m + j, (i + 1) * m + j);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m - 1; j++)
      if (!a[i][j] && !a[i][j + 1])
        dsu.tryUnion(i * m + j, i * m + j + 1);
  if (dsu.getRoot(0) == dsu.getRoot(m * n - 1)) {
    puts("0");
    return 0;
  }
  for (--k; k >= 0; --k) {
    int i = steps[k].first, j = steps[k].second;
    a[i][j] = false;
    for (int di = -1; di <= 1; di++) {
      for (int dj = -1; dj <= 1; dj++) {
        if (di*di+dj*dj==1 && i+di>=0 && i+di<n && j+dj>=0 && j+dj<m && !a[i+di][j+dj]) {
          dsu.tryUnion(i * m + j, (i + di) * m + j + dj);
          if (dsu.getRoot(0) == dsu.getRoot(m * n - 1)) {
            printf("%d\n", k + 1);
            return 0;
          }
        }
      }
    }
  }
}
